package com.aj.http.response;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.aj.databases.entry.TaskInfo;

public class QueryTaskListResponse extends BaseRespond {
	List<TaskInfo> taskInfoList = new ArrayList<TaskInfo>();

	public QueryTaskListResponse(JSONObject json) {
		super(json);
		try {
			JSONObject jsonObject = common.getResult();
			if (jsonObject != null && jsonObject.has("list")
					&& !jsonObject.isNull("list")) {
				JSONArray jsonArray = jsonObject.getJSONArray("list");
				JSONObject tempJSONObject = null;
				TaskInfo taskInfo = null;
				for (int i = 0; i < jsonArray.length(); i++) {
					tempJSONObject = jsonArray.getJSONObject(i);
					taskInfo = new TaskInfo();
					if (!tempJSONObject.isNull("id")) {
						taskInfo.setId(tempJSONObject.getString("id"));
					}
					if (!tempJSONObject.isNull("content")) {
						taskInfo.setContent(tempJSONObject.getString("content"));
					}
					if (!tempJSONObject.isNull("imgUrl")) {
						taskInfo.setImgUrl(tempJSONObject.getString("imgUrl"));
					}
					if (!tempJSONObject.isNull("audioUrl")) {
						taskInfo.setAudioUrl(tempJSONObject
								.getString("audioUrl"));
					}
					if (!tempJSONObject.isNull("userId")) {
						taskInfo.setUserId(tempJSONObject.getString("userId"));
					}
					if (!tempJSONObject.isNull("nickName")) {
						taskInfo.setNickName(tempJSONObject
								.getString("nickName"));
					}
					if (!tempJSONObject.isNull("type")) {
						taskInfo.setType(tempJSONObject.getString("type"));
					}
					if (!tempJSONObject.isNull("status")) {
						taskInfo.setStatus(tempJSONObject.getString("status"));
					}
					if (!tempJSONObject.isNull("createDate")) {
						taskInfo.setCreateDate(tempJSONObject
								.getString("createDate"));
					}
					if (!tempJSONObject.isNull("sendTime")) {
						taskInfo.setSendTime(tempJSONObject
								.getString("sendTime"));
					}
					if (!tempJSONObject.isNull("totalResults")) {
						taskInfo.setTotalResults(tempJSONObject
								.getString("totalResults"));
					}
					taskInfoList.add(taskInfo);
				}
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
	}

	public List<TaskInfo> getTaskInfoList() {
		return taskInfoList;
	}

	public void setTaskInfoList(List<TaskInfo> taskInfoList) {
		this.taskInfoList = taskInfoList;
	}

}
